package sw6.launcher;

import sw6.lib.Settings;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.view.Gravity;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

public class Icon extends LinearLayout {
	ImageView imageView;
	TextView textView;
	
	public Icon(Context context) {
		super(context);
		
		imageView = new ImageView(context);
		textView = new TextView(context);
		
		imageView.setLayoutParams(new GridView.LayoutParams(85, 85));
        imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
        imageView.setPadding(8, 8, 8, 8);
        
        setGravity(Gravity.CENTER_HORIZONTAL);
        textView.setGravity(Gravity.CENTER_HORIZONTAL);
        setOrientation(VERTICAL);
        
        addView(imageView);
	}

	public void setImageDrawable(Drawable drawable) {
		imageView.setImageDrawable(drawable);
	}

	public void setText(String text) {
		removeAllViews();
		addView(imageView);
		if (Settings.getUserProfile(getContext()).canRead()) {
			textView.setText(text);
			addView(textView);
		}
	}

}
